package com.google.code.rgbgoesbetween.gui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.google.code.rgbgoesbetween.R;
import com.google.code.rgbgoesbetween.data.Item;
/**
 * The adapter used to give specific display information and layout. It also
 * holds the data for a ListView.
 * @author Avanyali
 *
 */
public class ItemAdapter extends ArrayAdapter<Item> {

	private Context context;
	private Item[] objects;

	public ItemAdapter(Context context, Item[] objects) {
		super(context, R.layout.adapter_row, objects);
		this.context = context;
		this.objects = objects;
	}
	
	@Override
	  public View getView(int position, View convertView, ViewGroup parent) {
	    LayoutInflater inflater = (LayoutInflater) context
	        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    View rowView = inflater.inflate(R.layout.adapter_row, parent, false);
	    TextView nameView = (TextView) rowView.findViewById(R.id.adapter_name_field);
	    TextView descView = (TextView) rowView.findViewById(R.id.adapter_desc_field);
	    nameView.setText(objects[position].getName());
	    descView.setText(objects[position].getDescription());

	    return rowView;
	  }
}
